// Package user_follow 模型
package user_follow

import (
	// "gitee.com/sweetsunnyflower/carpooling-server-go/pkg/logger"
	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models/driver"
	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/database"
)

const (
	_ = iota
	FOLLOW_DRIVER
	FOLLOW_PASSENGER
)

type User struct {
	models.BaseModel

	Avatar string `json:"avatar"`
	Name   string `json:"name"` // 姓名

	Email  string         `json:"email"`
	Phone  string         `json:"phone"`
	Gender uint8          `gorm:"comment:性别 2:女,1:男;default:0;" db:"gender" json:"gender" form:"gender"`
	Driver *driver.Driver `json:"driver"`

	models.CommonTimestampsField
}

// 乘客关注司机表
type UserFollow struct {
	models.BaseModel

	UserId   uint64 `gorm:"column:user_id" db:"user_id" json:"user_id" form:"user_id"`         //关注者ID
	FollowId uint64 `gorm:"column:follow_id" db:"follow_id" json:"follow_id" form:"follow_id"` //被关注者ID
	Type     uint8  `gorm:"column:type;comment:1乘客关注司机 2司机关注乘客;" db:"type" json:"type" from:"type"`
	Follow   *User  `gorm:"foreignKey:follow_id" json:"follow"`

	models.CommonTimestampsField
}

func (userFollow *UserFollow) Create() {
	database.DB.Create(&userFollow)
}

func (userFollow *UserFollow) Save() (rowsAffected int64) {
	result := database.DB.Save(&userFollow)
	return result.RowsAffected
}

func (userFollow *UserFollow) Delete() (rowsAffected int64) {
	result := database.DB.Delete(&userFollow)
	return result.RowsAffected
}
